import { getStream } from '../Core/connect'
import { Vector3 } from '../Math/Vector3'
import * as MathUtils from '../Math/MathUtils'
/* 
    需要添加多个方法
    开始点击绘制围栏方法，
    结束绘制围栏方法并且保存或返回
    根据数组生成围栏
    清除已生成围栏

*/

export class Fence  {
    uuid: string
    segmentLenth:number
    staticmeshIndex:number
    poslist:Array<Vector3>
    constructor(poslist:Array<Vector3>,segmentLenth:number,staticmeshIndex:number) {
        this.uuid = MathUtils.generateUUID()
        this.segmentLenth = segmentLenth
        this.staticmeshIndex = staticmeshIndex
        this.poslist = poslist
        this.init()
    }
    init() {
        const stream = getStream()
        const str = {
            Fencefuncetion: 'addFenceByList', 
            ids: `${this.uuid}`,
            segmentLenth: `${this.segmentLenth}`,
            staticmeshIndex: `${this.staticmeshIndex}`,
            poslist: this.poslist
        }
        stream.emitUIInteraction(str)
    }

    //设置围栏模型序号
    setStaticmeshIndex(index:number){
        const stream = getStream()
        this.staticmeshIndex = index
        const str = {
            Fencefuncetion: 'setStaticmeshIndex', 
            ids: `${this.uuid}`,
            staticmeshIndex: `${this.staticmeshIndex}`,
        }
        stream.emitUIInteraction(str)
    }
    //设置围栏单个模型长度
    setSegmentLenth(length:number){
        const stream = getStream()
        this.segmentLenth = length
        const str = {
            Fencefuncetion: 'setSegmentLenth', 
            ids: `${this.uuid}`,
            segmentLenth: `${this.segmentLenth}`,
        }
        stream.emitUIInteraction(str)
    }
    destroy(){
        const stream = getStream()
        const str = {
            Fencefuncetion: 'destroyFence', 
            ids: `${this.uuid}`,
        }
        stream.emitUIInteraction(str)
    }



    clearAllFence(){
        let stream = getStream()
        const message = {Fencefuncetion: 'clearAllFence'}
        stream.emitUIInteraction(message)
    }
    clearFenceById(ids:string){
        let stream = getStream()
        const message = { 
            Fencefuncetion: 'clearFenceById', 
            ids: `${ids}`
        }
        stream.emitUIInteraction(message)
    }

}
